﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

using Gift.DAL;
using Gift.Model;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;

namespace WebApp.admin.order
{
    public partial class orderReportForms : BaseAdmin
    {
        // Fields

    
        protected string webSiteXmlPaht = "/cn/xml/website_set.xml";

        // Methods
        protected void Page_Load(object sender, EventArgs e)
        {
      
                ReportDocument document = new ReportDocument();
                if ((base.Request.QueryString["id"] != null) && (base.Request.QueryString["orderNo"] != null))
                {
                    tbOrder oOrder = BaseFactory.theOrder.GetModel(Convert.ToInt32(base.Request.QueryString["id"]));
                    DataTable orderGoodsEntitysByOrderNo = BaseFactory.theOrderGoodsEntitys.GetOrderGoodsEntitysByOrderNo(base.Request.QueryString["orderNo"]);
                    document.Load(base.Server.MapPath("/report/OrderCrystalReport.rpt"));
                    document.SetDataSource(orderGoodsEntitysByOrderNo);
                    this.crvOrder.ReportSource = document;
                    document.SetParameterValue("title", "订单");
                    XmlDocument document2 = new XmlDocument();
                    document2.Load(base.Server.MapPath(this.webSiteXmlPaht));
                    XmlElement element = document2.SelectSingleNode("set/cn_enterprise_name") as XmlElement;
                    document.SetParameterValue("companyName", element.GetAttribute("value"));
                    if (oOrder != null)
                    {
                        document.SetParameterValue("orderNo", oOrder.orderNo);
                        document.SetParameterValue("createTime",oOrder.createTime.ToString("yyyy年MM月dd日HH时mm分ss秒"));
                        document.SetParameterValue("consignee", oOrder.consignee);
                        document.SetParameterValue("region", oOrder.region);
                        document.SetParameterValue("address",oOrder.address);
                        document.SetParameterValue("zipCode", oOrder.zipcode);
                        document.SetParameterValue("telephone", oOrder.telephone == null ? "" : oOrder.telephone); 
                        document.SetParameterValue("mobile", oOrder.mobile);
                        document.SetParameterValue("deliveryWay", oOrder.deliveryMoney);
                        document.SetParameterValue("payment", oOrder.payment);
                        document.SetParameterValue("operator", base.Administrator.AdminUser);
                        document.SetParameterValue("goodsTotal", string.Format("{0:C}", oOrder.goodsTotal.ToString()));
                        document.SetParameterValue("orderTotal", string.Format("{0:C}", oOrder.orderTotal.ToString()));
                        document.SetParameterValue("deliveryMoney", string.Format("{0:C}", oOrder.deliveryMoney.ToString()));
                        document.SetParameterValue("postscript", oOrder.postscript == null ? "" : oOrder.postscript);
                        document.SetParameterValue("orderRemark", oOrder.orderRemark == null ? "" : oOrder.orderRemark.Replace("<br />", " ").Replace("&nbsp;", ""));
                    }
                }
            
        }
    }
}